package ee.ttu.rakarh.commands;

import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ee.ttu.rakarh.model.data.dao.ItemDAO;
import ee.ttu.rakarh.model.data.dao.ItemDAOImpl;
import ee.ttu.rakarh.model.data.entities.Item;
import ee.ttu.rakarh.model.data.entities.ItemType;

public class SearchItemCommand implements Command {

	@Override
	public Boolean execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		Collection<Item> items = new ArrayList<Item>();
		
		String searchPhrase = request.getParameter("query");
		
		ItemDAO itemImpl = new ItemDAOImpl();
		items = itemImpl.getItemsBySearchName(searchPhrase);
		
		ItemType itemType = new ItemType();
		itemType.setTypeName("Otsingu tulemused '" + searchPhrase + "':");
		
		request.setAttribute("type", itemType);
		request.setAttribute("items", items);
		
		return null;
	}

}
